package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ExecutionDAO;
import entity.Execution;;

@WebServlet("/servlet/ExcutionServlet")
public class ExcutionServlet extends HttpServlet{
	private ExecutionDAO exdao=new ExecutionDAO();
	private String action ;
	
	 public ExcutionServlet() {
	        super();
	    }

	 public void doGet(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
	        doPost(request,response);
	  }

	  public void doPost(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
		  request.setCharacterEncoding("UTF-8");
		  this.action = request.getParameter("action");
	      if (action.equals("edit"))
	      {
	    	  execute_edit(request);
	      }
	      else if (action.equals("finish"))
	      {
	    	  execute_finish(request);
	      }
	      else;
	      	request.getRequestDispatcher("/execution.jsp").forward(request, response);   	
	  }

	private void execute_edit(HttpServletRequest request) {
		 try {

			 this.exdao.execution_edit(request.getParameter("cno"));
	        
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
	}
	
	private void execute_finish(HttpServletRequest request) {
		 try {

			 this.exdao.execution_finish(request.getParameter("cno"));
	        
		 } catch (Exception ex) {
	            request.setAttribute("errormsg", ex.getMessage());
	     }
	}
}
